package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysProcess;
import com.ruoyi.system.service.ISysProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程信息操作处理
 */
@Api(tags = "流程管理")
@RestController
@RequestMapping("/system/process")
public class SysProcessController extends BaseController {

    @Autowired
    private ISysProcessService iSysProcessService;

    /**
     * 分页获取流程列表
     * @param sysProcess
     * @return
     */
    @ApiOperation("分页查询所有流程")
    @PreAuthorize("@ss.hasPermi('system:process:list')")
    @GetMapping("/list")
    public TableDataInfo getAllProcesses(SysProcess sysProcess){
        startPage();
        List<SysProcess> sysProcesses = iSysProcessService.selectAllProcesses(sysProcess);
        return getDataTable(sysProcesses);
    }

    /**
     * 根据条件分页查询流程列表
     * @param sysProcess
     * @return
     */
    @ApiOperation("分页条件查询流程")
    @PreAuthorize("@ss.hasPermi('system:process:query')")
    @GetMapping("/query")
    public TableDataInfo getProcessList(SysProcess sysProcess){
        startPage();
        List<SysProcess> sysProcesses = iSysProcessService.selectProcessList(sysProcess);
        return getDataTable(sysProcesses);
    }

    /**
     * 新增流程
     * @param sysProcess
     * @return
     */
    @ApiOperation(value = "新增流程")
    @Log(title = "流程新增",businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('system:process:add')")
    @PostMapping
    public AjaxResult processAdd(@RequestBody SysProcess sysProcess){
        sysProcess.setCreateBy(getUsername());

        return toAjax(iSysProcessService.insertProcess(sysProcess));
    }

    /**
     * 修改流程
     * @param sysProcess
     * @return
     */
    @ApiOperation("修改流程")
    @Log(title = "流程修改",businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('system:process:edit')")
    @PutMapping
    public AjaxResult processEdit(@RequestBody SysProcess sysProcess){
        sysProcess.setUpdateBy(getUsername());
        return toAjax(iSysProcessService.updateProcess(sysProcess));
    }

    /**
     * 批量删除流程
     * @param ids
     * @return
     */
    @ApiOperation("删除流程")
    @Log(title = "流程删除",businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('system:process:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult processRemove(@PathVariable Long[] ids){
        return toAjax(iSysProcessService.processRemove(ids));
    }

}
